/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package session;

import entity.PianoStudio;
import entity.PianoStudioPK;
import entity.Studente;
import facade.EsameFacadeLocal;
import facade.PianoStudioFacadeLocal;
import facade.StudenteFacadeLocal;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;

/**
 *
 * @author grillo
 */
@Stateless
public class EditPianoBean implements EditPianoLocal {
    @EJB
    EsameFacadeLocal esameFacade;
    @EJB
    StudenteFacadeLocal studenteFacade;
    @EJB
    PianoStudioFacadeLocal pianoStudioFacade;

    public void addEsame(Integer matricola, Integer idEsame) {

        PianoStudio p = new PianoStudio();
        p.setEsame(esameFacade.find(idEsame));
        p.setStudente(studenteFacade.find(matricola));
        p.setPianoStudioPK(new PianoStudioPK(matricola, idEsame));
        p.setLode(false);
        p.setStato(false);
        p.setVoto(0);

        Studente st = studenteFacade.find(matricola);
        List<PianoStudio> lista = st.getPianoStudioCollection();
        lista.add(p);
        st.setPianoStudioCollection(lista);

        studenteFacade.edit(st);
    }

    public void removeEsame(Integer matricola, Integer idEsame) {

        PianoStudio p = pianoStudioFacade.find(new PianoStudioPK(matricola, idEsame));

        Studente st = studenteFacade.find(matricola);
        List<PianoStudio> lista = st.getPianoStudioCollection();
        lista.remove(p);
        st.setPianoStudioCollection(lista);

        pianoStudioFacade.remove(p);
    }
}